Next | Prev | Up | Top | Contents | Index

ioctl Support

In addition to the usual 64-bit conversion worries (longs and pointers becoming 64-bits, ints remaining 32-bits), drivers may need to support ioctls from user programs. Since user programs may be 32-bit or 64-bit, data items from those programs may need to be converted into the appropriate internal form for the driver. (The driver needs to know whether a pointer or a long from a user program should be treated as a 32-bit quantity or a 64-bit quantity.) To ease the driver conversion, a new system intrinsic that informs the driver of the size of various types for the currently executing user has been supplied. See the ioctl(D2) man page.

The following definitions are available in sys/types.h and sys/ddi.h:

/* Since device drivers may need to know which ABI the 
/* current user process is running under in order to use the /* correct types, we provide the following structure. See 
/* ddi.h for the definition of userabi().
 * All sizes are in bytes. */
typedef struct __userabi {
    short uabi_szint;
    short uabi_szlong;
    short uabi_szptr;
    short uabi_szlonglong;
} __userabi_t;

/* function: userabi(__userabi_t *)
 * purpose: determine the size int bytes of various C types 
 * in the ABI under which the current user process is 
 * running. 0 indicates success,nonzero indicates failure. 
 * This function must only be called from a user's 
 * context, and the values copied into __userabi_t are only 
 * valid for the process executing when userabi is called.
 */
int
userabi(__userabi_t *currentabi)

Pointers

Pointers in memory buffers need to be double-word aligned to avoid address errors when the pointers are loaded. Both pointers and longs must be aligned on 8-byte boundaries; neither should be cast to int because the int structure is only 32-bits wide.


Hardware Data Copying

When copying data to or from a hardware device, drivers should use the functions hwcpin and hwcpout rather than bcopy. The reason is that the kernel bcopy routine is optimized for memory access and may use double-word loads and stores, which may not be supported by the hardware device. The routines hwcpin and hwcpout perform only word (or byte and half-word) operations.


Next | Prev | Up | Top | Contents | Index